package com.lrr.controller;

import com.github.pagehelper.PageInfo;
import com.lrr.entity.Accountant;
import com.lrr.entity.AccountantType;
import com.lrr.entity.QueryVo;
import com.lrr.service.AccountantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class AccountantController {

    @Autowired
    AccountantService service;

    @RequestMapping("/list")
    public String list(QueryVo vo, @RequestParam(defaultValue = "1") Integer pageNum, Model model){
        PageInfo<Accountant> info = service.list(vo,pageNum);
        model.addAttribute("info",info);
        model.addAttribute("vo",vo);
        return "accountant_list";
    }

    @RequestMapping("/toAdd")
    public String toAdd(Accountant accountant,Model model){
        model.addAttribute("accountant",accountant);
        return "accountant_add";
    }

    @ResponseBody
    @RequestMapping("/selectTypes")
    public List<AccountantType> selectTypes(){
        return service.selectTypes();
    }

    @RequestMapping("/add")
    public String add(Accountant accountant){
        service.add(accountant);
        return "redirect:list";
    }

    @ResponseBody
    @RequestMapping("/delAll")
    public int delAll(String ids){
        return service.delAll(ids);
    }
}
